home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.8 KB | 63 lines | [TEXT/GEOL] |
- Item forwarded by X0501 to MACAPP$
-
- Item 2718606 5-April-88 21:54
-
- From: X0501 MacApp Developers Assoc, C. Nelson
-
- To: N0658 ESL, Robert Penland, ASC
-
- Sub: Re: MacApp datafields
-
- Robert,
-
- The answer to your question is as you have guessed. The dreaded heap
- compaction can and usually does occur between method calls. I do not know the
- exact rules for when it occurs between method calls (Larry, Curt or David?).
- What you have shown is dangerous code.
-
- The solution to your problem is to either preallcoate the space in a global
- structure for n number of DSPCommand Records and keep the index OR allocate the
- space on the heap in each TMyRequester’s Init method and then keep a reference
- (Pointer) in the object. Allocations made with pointers should be freed by your
- own methods or by the free in the object.
-
- Here would be my suggested work-around to your problem assuming each
- TMyRequester must have its own DSPCommand RECord:
-
- PtrDSPCommand = ^DSPCommand;
- DSPCommandREC=RECORD
- Command1:INTEGER;
- Command2:INTEGER;
- Command3:Str255;
- END;
-
- then in your CLASS (OBJECT) definition do the following:
-
- TMyRequester = TOBJECT(TRequester)
- fDSPCommand: PtrDSPCommand;
- …
- PROCEDURE TMyRequester.IMyRequester;
- PROCEDURE TMyRequester.Free; OVERRIDE;
- …
- END
-
- PROCEDURE TMyRequester.IMyRequester;
- VAR myPtr : Ptr;
- BEGIN
- myPtr := NewPtr(SIZEOF(DSPCommandREC));
- FailNil(Ptr);
- fDSPCommand := myPtr;
- END
-
- PROCEDURE TMyRequester.Free;
- BEGIN
- DisposPtr(fDSPCommand);
- INHERITED Free;
- END
-
- OF course I’ve left out all the error handling you would probably want to do if
- an allocation fails. or checking if it was OK to free the data.
-
- Hope this helps.... Carl
-
-